// pages/oilStore/oilDetail.js
import { find as warehouseFind, del as warehouseDel } from '../../api/warehouse';
import { find } from "../../api/member";
import { datetime } from "../../utils/util";

Page({

  /**
   * 页面的初始数据
   */
  data: {
    id: '',
    warehouse: {},
    date: '',
    city: '',
    customer:{}
  },

  goToLog() {
    // wx.navigateTo({
    //   url: '/pages/oilStore/operation_log',
    // })
    console.log(goToLog);
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    //获取上个页面，点击的油库id
    this.data.id = options.id;
    this.getFindOilStore(options.id);
  },

  getFindOilStore(id) {
    let supply;
    warehouseFind(id).then(res => {
      let date = datetime(res.data.warehouse.createDate)
      console.log(res,'youku');
      this.setData({
        warehouse: res.data.warehouse,
        customer:res.data.customer,
        date: date,
        city: res.data.area.fullName
      })

    })

  },
  delOilStore() {
    let id = this.data.id
    wx.showModal({
      title: '提示',
      content: '是否删除该油库',
      success(res) {
        if (res.confirm) {
          warehouseDel(id).then(()=>{
            wx.navigateBack();
          })
        } else if (res.cancel) {
          return
        }
      }
    });
    console.log(this.data.warehouse.name);
   
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})